package org.dftproject.genesis.ui.pages.summary.details;

import org.dftproject.genesis.data.IAttribute;
import org.dftproject.genesis.ui.figures.ColumnData;
import org.dftproject.genesis.ui.pages.summary.sources.FootnoteContainer;
import org.dftproject.genesis.ui.pages.summary.sources.FootnoteMarker;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.text.FlowPage;
import org.eclipse.draw2d.text.ParagraphTextLayout;
import org.eclipse.draw2d.text.TextFlow;

public class NoteFigure extends Figure {

	private final FootnoteContainer footnoteContainer;

	private final TextFlow textFlow;
	private FootnoteMarker footnoteMarker;

	public NoteFigure(FootnoteContainer footnoteContainer) {
		this.footnoteContainer = footnoteContainer;
		
		ToolbarLayout layout = new ToolbarLayout(true);
		layout.setSpacing(10);
		setLayoutManager(layout);
		
		FlowPage flowPage = new FlowPage();

		textFlow = new TextFlow();
		textFlow.setLayoutManager(new ParagraphTextLayout(textFlow, ParagraphTextLayout.WORD_WRAP_SOFT));
		flowPage.add(textFlow);

		add(flowPage, new ColumnData(1));
	}
	
	public String getText(String text) {
		return textFlow.getText();
	}

	public void setText(String text) {
		textFlow.setText(text);
	}

	public void addSource(IAttribute sourceAttribute) {
		if (footnoteMarker == null) {
			footnoteMarker = new FootnoteMarker(footnoteContainer);
			add(footnoteMarker);
		}
		
		footnoteMarker.addSource(sourceAttribute);
	}

}
